package com.woniuxy.special.config;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MessageConfig {

    /**
     * 创建消息恢复器
     */
    @Bean
    public MessageRecoverer messageRecoverer(RabbitTemplate rabbitTemplate) {
        return new RepublishMessageRecoverer(rabbitTemplate,"errorExchange","error");
    }

    /**
     * 监听交换机和队列的消息的监听器
     */
    @Bean
    public PublishMqConfig setPublishMqConfigListener(RabbitTemplate rabbitTemplate) {
        PublishMqConfig publishMqConfig = new PublishMqConfig();
        rabbitTemplate.setReturnCallback(publishMqConfig);
        rabbitTemplate.setConfirmCallback(publishMqConfig);
        return publishMqConfig;
    }
}
